package org.example;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.example.domain.User;
import org.example.domain.Verse;
import org.example.mapper.UserMapper;
import org.example.mapper.VerseMapper;

import java.io.IOException;
import java.util.Map;

public class Main {

    static SqlSessionFactory sqlSessionFactory;

    public static void main(String[] args) {
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        try {
            sqlSessionFactory = builder.build(Resources.getResourceAsReader("mybatis-config.xml"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        try(SqlSession sqlSession = sqlSessionFactory.openSession()){
            final UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
            final User user = userMapper.selectUser(1);
//            final User user = sqlSession.selectOne("org.example.mapper.UserMapper.selectUser", 1);
            System.out.println(user.toString());
//            final VerseMapper verseMapper = sqlSession.getMapper(VerseMapper.class);
//            final Verse verse = verseMapper.selectOne(5);
//            System.out.println(verse);

            final VerseMapper verseMapper = sqlSession.getMapper(VerseMapper.class);
            final Map<String, Object> map = verseMapper.selectOne(5);
            System.out.println(map);


        }

    }
}
